package com.zzxx.www.dao.impl;

import com.zzxx.www.dao.UserDao;
import com.zzxx.www.domain.User;
import com.zzxx.www.utils.DruidUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UserDaoImpl implements UserDao {
	private JdbcTemplate template = new JdbcTemplate(DruidUtil.getDataSource());
	@Override
	public List<User> findAll() {
		String sql = "select * from users";
		List<User> list = template.query(sql, new BeanPropertyRowMapper<>(User.class));
		return list;
	}

	@Override
	public void deleteById(int id) {
		String sql = "delete from users where id = ?";
		template.update(sql,id);
	}
}
